home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
newsgroups
/
misc.20000217-20000824
/
000038_news@columbia.edu _Tue Feb 22 10:40:25 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2020-01-01
|
3KB
Return-Path: <news@columbia.edu>
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id KAA18658
for <kermit.misc@watsun.cc.columbia.edu>; Tue, 22 Feb 2000 10:40:25 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id KAA15336
for kermit.misc@watsun.cc.columbia.edu; Tue, 22 Feb 2000 10:20:11 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Subject: Re: Array name passed to macro as argument?
Date: 22 Feb 2000 15:20:11 GMT
Organization: Columbia University
Message-ID: <88u9fb$ev5$1@newsmaster.cc.columbia.edu>
To: kermit.misc@columbia.edu
In article <88u6ql$vmg$1@nnrp1.deja.com>,
Peter Easthope <peter_easthope@gulfnet.pinc.com> wrote:
: ; Can the name of an array be passed to a macro via an
: ; argument? This message can be interpreted as an example
: ; but the syntax fails. Any suggestions?
: ; ================================================
: ; pass the name of an array to Test as an argument.
: def Test {
: echo {\%1[1]}
: echo {\%1[2]}
: }
:
: declare \&d[2]
: def \&d[1] {Sea}
: def \&d[2] {urchin}
:
By the way, in C-Kermit 7.0 / K95 1.1.19, you can write this more
simply as:
declare \&d[] = Sea urchin
: echo {\&d[1]}
: echo {\&d[2]}
: echo {Now try passing the array name to Test.}
: Test \&d
:
Sure, an array name can be passed as an argument to a macro. The
question is, how to refer to it inside the macro? I confess, it's not
obvious.
There are two problems with your example:
1. "Test \&d" gives a syntax error. You have to double the backslash,
or you could use:
Test &a
and apply the backslash inside the macro.
2. But none of that helps, since "\%1[1]" is a compound construction.
When "\%1" is encountered, the variable expander is called to replace
it by its value, which is "\&d", and since this too starts with a
backslash, the variable expander is called again. But "\&d" has no
value.
Here's a version of your Test macro that works:
def test {
local \%x
.\%x := \\&\%1[1]
echo {\%x}
.\%x := \\&\%1[2]
echo {\%x}
}
First we construct the array reference string and assign it to a
temporary variable, \%x, the kind that is always evaluated recursively
(all the way down). Then by referring to it, rather than directly to the
constructed array element, we get the required full evaluation.
- Frank